//-----------------------------------------------------------------------------
// Copyright (c) 2011 David Waby
// Initially created on 14/11/2011
//-----------------------------------------------------------------------------

#include "Global.h"
#include "InventoryContainer.h"
#include "Container.h"

//-----------------------------------------------------------------------------
InventoryContainer::InventoryContainer(Item const * i_baseItem)
:	InventoryItem(i_baseItem)
{
	m_baseContainer = static_cast<Container const*>(i_baseItem);
	m_inventoryItems.reserve(m_baseContainer->m_capacity);
} 

//-----------------------------------------------------------------------------
InventoryContainer::~InventoryContainer()
{
} 

//-----------------------------------------------------------------------------
bool InventoryContainer::AddInventoryItemToContainer(InventoryItem * i_inventoryItem)
{
	if (m_inventoryItems.size() < m_inventoryItems.capacity()) 
	{
		m_inventoryItems.push_back(i_inventoryItem);
		return true;
	}

	return false;
}

//-----------------------------------------------------------------------------
bool InventoryContainer::RemoveInventoryItemFromContainer(InventoryItem const * i_inventoryItem)
{
	InventoryItem * inventoryItem = NULL;
	for (InventoryIterator iterator = m_inventoryItems.begin(); iterator != m_inventoryItems.end(); ++iterator)
	{
		if (i_inventoryItem == inventoryItem)
		{
			m_inventoryItems.erase(iterator);
			return true;
		}
	}

	return false;
}